package com.nti56.springboot.model;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.nti56.springboot.utils.TreeNodeUtil;

public class Module extends TreeGridNode{
	
	private String moduleId;
	private String parentId;
	private String moduleName;
	private String moduleCode;
	private String url;
	private String activate;
	
	
	public String getActivate() {
		return activate;
	}
	public void setActivate(String activate) {
		this.activate = activate;
	}
	public String getUrl() {
		return url;
	}
	public void setUrl(String url) {
		this.url = url;
	}
	/**
	 * 资源类型
	 * 1.url链接，2，按钮权限码，3，标签 accordion
	 */
	private String moduleType;
	
	/**
	 * 资源顺序
	 */
	private int sort;

	private Set<Role> roles = new HashSet<Role>();
	
	public int getSort() {
		return sort;
	}
	public void setSort(int sort) {
		this.sort = sort;
	}
	public String getModuleType() {
		return moduleType;
	}
	public void setModuleType(String moduleType) {
		this.moduleType = moduleType;
	}
	
	public String getModuleId() {
		return moduleId;
	}
	public void setModuleId(String moduleId) {
		this.moduleId = moduleId;
	}
	public String getModuleName() {
		return moduleName;
	}
	public void setModuleName(String moduleName) {
		this.moduleName = moduleName;
	}
	public String getModuleCode() {
		return moduleCode;
	}
	public void setModuleCode(String moduleCode) {
		this.moduleCode = moduleCode;
	}
	public Set<Role> getRoles() {
		return roles;
	}
	public void setRoles(Set<Role> roles) {
		this.roles = roles;
	}
	public String getParentId() {
		return parentId;
	}
	public void setParentId(String parentId) {
		this.parentId = parentId;
	}
	
	public static List<TreeNode> moduleList2TreeList(List<Module> mList){
		List<TreeNode> tList = new ArrayList<TreeNode>();
		for(Module m : mList){
			TreeNode t = new TreeNode();
			t.setId(m.getModuleId());
			t.setpId(m.getParentId());
			t.setText(m.getModuleName());
			t.setIconCls(m.getIconCls());
			t.setAttributes(TreeNodeUtil.getAttributes(m));
			tList.add(t);
		}
		return tList;
	}
}
